import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as session from "express-session"
import mongoose from 'mongoose';
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  app.enableCors({
    origin: 'http://127.0.0.1:5173',
    credentials: true,
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
  })
  app.useStaticAssets('public/images', {
    prefix: "/deliciousimg"
  })
  app.use(session({
    secret: 'yyds',
    name: "delicious",
    resave: false,
    rolling: true,
    saveUninitialized: false,
    cookie: { maxAge: 60 * 60 * 1000 }
  }))

  await mongoose.connect("mongodb://127.0.0.1:27017/", { dbName: "delicious" }).then(() => {
    console.log("连接成功")
  }).catch((err) => {
    console.log(err, '连接失败')
  })
  await app.listen(3001);
}
bootstrap();
